/* -*- c++ -*- */
/*
 * Copyright 2004 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 
 * Acknowledges: Paul Fuxjaeger of FTW (http://www.ftw.at/ueber-uns/team/~/paulf)
 
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <tx80211g_ofdm.h>
#include <gr_io_signature.h>
#include <iostream>
#include <stdexcept>
#include <string.h>

tx80211g_ofdm_obj_sptr 
tx80211g_make_ofdm_obj (int fft_size, int tones){
  return tx80211g_ofdm_obj_sptr (new tx80211g_ofdm_obj (fft_size , tones));
}

/*
 * 1 i/p and o/p.
 */
static const int MIN_IN = 1;
static const int MAX_IN = 1;
static const int MIN_OUT = 1;
static const int MAX_OUT = 1;

tx80211g_ofdm_obj::tx80211g_ofdm_obj (int fft_size, int tones)
  : gr_block ("ofdm_obj",
	      gr_make_io_signature (MIN_IN, MAX_IN, tones * sizeof (gr_complex)),
	      gr_make_io_signature (MIN_OUT, MAX_OUT, fft_size * sizeof (gr_complex))),
	      fft_size(fft_size),
	      tones(tones)
{
  
}

tx80211g_ofdm_obj::~tx80211g_ofdm_obj ()
{
  
}

int tx80211g_ofdm_obj::general_work (int ret, gr_vector_int &ninput_items,
			       gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
{
  const gr_complex *in = (const gr_complex *) input_items[0];
  gr_complex *out = (gr_complex *) output_items[0]; 
  int cnt=0;
  int i=0; 
      
  while(cnt < ret) {
    for (i = 0; i <= 26; i++)        
      out[i + (cnt * fft_size)] = in[i+26 + (cnt * tones)];
    for (i = 27 ; i <= 37 ; i++)
      out[i + (cnt * fft_size)] = 0;
    for (i = 38; i < fft_size ; i++)
      out[i + (cnt * fft_size)] = in[i-38 + (cnt * tones)];
    cnt++;
  }

  
  consume_each (ret);

  return ret;
}
